(function( $, undefined ) {

$.widget("ui.actions", {
    options : {
		edit: true,
		print: true,
		save: true
    },

    _create : function() {
		var self = this,

		uiMap = (self.uiMap) = $('<li>')
			.addClass('ui-state-default ui-corner-bottom actions')
			.attr('title', i18n.msg('mapOnOff'))
			.appendTo(this.element),
		uiMapContent = $('<span>')
			.addClass('ui-icon ui-icon-pin-w')
			.appendTo(uiMap);
		
		uiProp = (self.uiProp) = $('<li>')
			.addClass('ui-state-default ui-corner-bottom actions')
			.attr('title', i18n.msg('mapOnOff'))
			.appendTo(this.element),
		uiPropContent = $('<span>')
			.addClass('ui-icon ui-icon-gear')
			.appendTo(uiProp);
		
		uiSrc = (self.uiSrc) = $('<li>')
			.addClass('ui-state-default ui-corner-bottom actions')
			.attr('title', i18n.msg('mapOnOff'))
			.appendTo(this.element),
		uiSrcContent = $('<span>')
			.addClass('ui-icon ui-icon-wrench')
			.appendTo(uiSrc);
		
		uiAdd = (self.uiAdd) = $('<li>')
			.addClass('ui-state-default ui-corner-bottom actions')
			.attr('title', i18n.msg('addFiles'))
			.appendTo(this.element),
		uiAddContent = $('<span>')
			.addClass('ui-icon ui-icon-plus')
			.appendTo(uiAdd);
    },

	_getEvents : function(el, callback) {
		el.hover(
				function() {
					$(this).addClass("ui-state-hover");
				},
				function() {
					$(this).removeClass("ui-state-hover");
				}
			)
			.click(callback);
		return el;
	},

	_uiAddHandler : function() {
		conf.upForm.dialog('open');
	},

	_uiMapHandler : function() {
		var el        = $(this).children();
		var addClass  = el.hasClass('ui-icon-pin-w') ? 'ui-icon-pin-s' : 'ui-icon-pin-w';
		var rmClass   = el.hasClass('ui-icon-pin-w') ? 'ui-icon-pin-w' : 'ui-icon-pin-s';
		el.removeClass(rmClass).addClass(addClass);
		if (addClass == 'ui-icon-pin-s') {
			$("#application div.ui-tabs-panel:not(.ui-tabs-hide)").each(function(){
				$(this).mapped('show');
			});
			conf.mapped = true;
		} else {
			$("#application div.ui-tabs-panel").each(function(){
				$(this).mapped('disable');
				metricsHelper.reset();
			});
			conf.mapped = false;
		}
	},
	
	_uiPropHandler : function() {
		conf.propDlg.dialog('open');
	},
	
	_uiSrcHandler : function() {
		conf.srcDlg.dialog('open');
	},
	
	refresh : function(actions) {
		for (var i=0; i<actions.length; i++) {
			if (actions[i].visible == true) {
				eval('this.' + actions[i].name + '.removeClass("ui-state-disabled")');
				eval('this._getEvents(this.' + actions[i].name + ', this._' + actions[i].name + 'Handler)');
			} else {
				eval('this.' + actions[i].name + '.addClass("ui-state-disabled")');
				eval('this.' + actions[i].name + '.unbind()');
			}
		}
	},

    destroy: function() {
        $.Widget.prototype.destroy.apply( this, arguments );
    }
});

$.extend($.ui.actions, {
    version: "0.1"
});

}(jQuery));
